package com.immediatus.engine.modifier;


import com.immediatus.engine.contracts.Interpolator;

public abstract class BaseSingleValueChangeModifier<T> extends BaseDurationModifier<T>{

    private final float _value;

	public BaseSingleValueChangeModifier(final float duration_, final float value_) {
        super(duration_);
        this._value = value_;
	}

    public BaseSingleValueChangeModifier(final float duration_, final float value_, Interpolator interpolator_) {
        super(duration_, interpolator_);
        this._value = value_;
    }

	public BaseSingleValueChangeModifier(final float duration_, final float value_, final IModifierListener<T> listener_) {
		super(duration_, listener_);
        this._value = value_;
	}

    public BaseSingleValueChangeModifier(final float duration_, final float value_, final IModifierListener<T> listener_, Interpolator interpolator_) {
        super(duration_, listener_, interpolator_);
        this._value = value_;
    }

	protected BaseSingleValueChangeModifier(final BaseSingleValueChangeModifier<T> modifier_) {
		super(modifier_);
        this._value = modifier_._value;
	}

    protected abstract void onChangeValue(final T item_, final float secondsElapsed_, final float value_);

	@Override
	protected void onManagedInitialize(final T item_) {
	}

	@Override
	protected void onManagedUpdate(final float secondsElapsed_, final T item_) {
        final float interpolation = getInterpolator().interpolate(secondsElapsed_ / getDuration());
        this.onChangeValue(item_, secondsElapsed_, this._value * interpolation);
	}
}
